import asyncio
from passlib.context import CryptContext
import getpass

from db.db import async_session
from models.models import User


pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")


async def create_super_user():
    """Создает супер пользователя."""
    username = input("Enter username: ")
    password = getpass.getpass("Enter password: ")
    repeat_password = getpass.getpass("Repeat password: ")

    if password != repeat_password:
        print("Passwords do not match")
        return

    password_hash = pwd_context.hash(password)
    async with async_session() as session:
        super_user = User(
            username=username,
            login=username,
            hashed_password=password_hash,
        )
        session.add(super_user)
        await session.commit()
    print("Super user created")


if __name__ == "__main__":
    asyncio.run(create_super_user())
